package com.c2b.algorithm.leetcode.base;

/**
 * <a href="https://leetcode.cn/problems/design-hashset/">设计哈希集合(Design HashSet)</a>
 * <p>不使用任何内建的哈希表库设计一个哈希集合（HashSet）。</p>
 * <p>
 * 实现 MyHashSet 类：
 *      <ul>
 *          <li>void add(key) 向哈希集合中插入值 key 。</li>
 *          <li>bool contains(key) 返回哈希集合中是否存在这个值 key 。</li>
 *          <li>void remove(key) 将给定值 key 从哈希集合中删除。如果哈希集合中没有这个值，什么也不做。</li>
 *      </ul>
 * </p>
 *
 * <p>
 * <b>示例：</b>
 * <pre>
 * 示例：
 *      输入：
 *          ["MyHashSet", "add", "add", "contains", "contains", "add", "contains", "remove", "contains"]
 *          [[], [1], [2], [1], [3], [2], [2], [2], [2]]
 *      输出：
 *          [null, null, null, true, false, null, true, null, false]
 *      解释：
 *          MyHashSet myHashSet = new MyHashSet();
 *          myHashSet.add(1);      // set = [1]
 *          myHashSet.add(2);      // set = [1, 2]
 *          myHashSet.contains(1); // 返回 True
 *          myHashSet.contains(3); // 返回 False ，（未找到）
 *          myHashSet.add(2);      // set = [1, 2]
 *          myHashSet.contains(2); // 返回 True
 *          myHashSet.remove(2);   // set = [1]
 *          myHashSet.contains(2); // 返回 False ，（已移除）
 * </pre>
 * </p>
 * <p>
 * <b>提示：</b>
 * <li>0 <= key <= 10^6</li>
 * <li>最多调用 10^4 次 add、remove 和 contains</li>
 * </p>
 *
 * @author c2b
 * @see LC0705DesignHashSet_S 设计哈希集合(Design HashSet)
 * @see LC0706DesignHashMap_S 设计哈希映射(Design HashMap)
 * @see LC707DesignLinkedList_M 设计链表(Design Linked List)
 * @see LC1206DesignSkiplist_H 设计跳表(Design Skiplist)
 * @since 2023/5/10 9:09
 */
public class LC0705DesignHashSet_S {

    static class MyHashSet {
        boolean[] valArr = new boolean[1000001];

        public MyHashSet() {

        }

        public void add(int key) {
            valArr[key] = true;
        }

        public void remove(int key) {
            valArr[key] = false;
        }

        public boolean contains(int key) {
            return valArr[key];
        }
    }

    static class Node {
        public Integer key;
        public Node next;

        public Node(Integer key) {
            this.key = key;
        }
    }

    public static void main(String[] args) {
        MyHashSet myHashSet = new MyHashSet();
        myHashSet.add(1);
        myHashSet.add(2);
        System.out.println(myHashSet.contains(1));
        System.out.println(myHashSet.contains(3));
        myHashSet.add(2);
        myHashSet.contains(2);
        myHashSet.remove(2);
        System.out.println(myHashSet.contains(2));
    }

}
